//package com.applink.sell_proof.fragment;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Observable;
//import java.util.Observer;
//
//import android.database.Cursor;
//import android.os.AsyncTask;
//import android.os.Bundle;
//import android.os.Handler;
//import android.os.Message;
//import android.support.v4.app.LoaderManager.LoaderCallbacks;
//import android.support.v4.content.CursorLoader;
//import android.support.v4.content.Loader;
//import android.util.Log;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.ExpandableListView;
//import android.widget.ListView;
//import android.widget.ExpandableListView.OnChildClickListener;
//import android.widget.TextView;
//
//import com.actionbarsherlock.app.SherlockFragment;
//import com.applink.sell_proof.BasePagerActivity;
//import com.applink.sell_proof.R;
//import com.applink.sell_proof.adapter.RedeemAdapter;
//import com.applink.sell_proof.adapter.RewardStatementAdapter;
//import com.applink.sell_proof.api.DataHelper;
//import com.applink.sell_proof.constant.Constant;
//import com.applink.sell_proof.database.EMarketingContentProvider;
//import com.applink.sell_proof.database.table.RewardDBHelper;
//import com.applink.sell_proof.model.NewReward;
//
//public class RewardStatementFragment extends SherlockFragment implements LoaderCallbacks<Cursor>,OnChildClickListener{
//	
////	protected ViewGroup mLayout;
////	private int mReferenceLoading = 2;
////	private View mHeaderReward;
////	private static final int SHOW_DATA = 0;
////	private RewardStatementAdapter mAdapter;
////	private ListView listRewardStatement;
////	@Override
////	public View onCreateView(LayoutInflater inflater, ViewGroup container,
////			Bundle savedInstanceState) {		
////		init(inflater,container);
////		setHasOptionsMenu(true);
////		((BasePagerActivity)getActivity()).showProgressDialog(R.id.reward_statement_container_loading);
////		return mLayout;
////		
////	}
////	
////	@Override
////	public void onResume() {
////		super.onResume();
////		//new loadData().execute();
//////		DataHelper.getInstance().addObserver(this);
//////		DataHelper.getInstance().getReward();
//////		DataHelper.getInstance().getOpportunityByStatus(
//////				"'" + ItemStatus.APPROVED + "'",
//////				this.getClass().getName());
//////		DataHelper.getInstance().getClaimByStatus(
//////				"'"  + ItemStatus.SUBMITTED +  "'", this.getClass().getName());
//////		DataHelper.getInstance().addObserver(this);
//////		DataHelper.getInstance().getEarnedStatement();
//////		DataHelper.getInstance().getListRedeem();
//////		mReferenceLoading = 2;
////	}
////	
////	
////	@Override
////	public void onActivityCreated(Bundle savedInstanceState) {
////		super.onActivityCreated(savedInstanceState);
////		getActivity().getSupportLoaderManager().initLoader(0, null, this);
////		new loadData().execute();
////	}
////	
////	private class loadData extends AsyncTask<Void, Void, Integer>{
////
////		@Override
////		protected Integer doInBackground(Void... params) {
////			DataHelper.getInstance().getReward();
////			return 0;
////		}
////		
////		@Override
////		protected void onPostExecute(Integer result) {
////			mHandler.sendEmptyMessage(SHOW_DATA);
////			super.onPostExecute(result);
////		}
////		
////	}
////	
////	private Handler mHandler = new Handler(new Handler.Callback() {
////		
////		@Override
////		public boolean handleMessage(Message msg) {
////			switch (msg.what) {
////			case SHOW_DATA:
////				Constant.dataReward = RewardDBHelper.getAllReward();
////				if(mAdapter == null){
////					mAdapter = new RewardStatementAdapter(Constant.dataReward);
////					listRewardStatement.setAdapter(mAdapter);
////				}else{
////					mAdapter.notifyDataSetChanged();
////				}
////				break;
////
////			default:
////				break;
////			}
////			return false;
////		}
////	});
////
//////	@Override
//////	public void update(Observable observable, Object data) {
//////		observable.deleteObserver(this);
//////		mReferenceLoading--;
//////		if(mReferenceLoading == 0) ((BasePagerActivity)getActivity()).hideProgressDialog(R.id.reward_statement_container_loading);
//////		ExpandableListView listview = ((ExpandableListView)mLayout.findViewById(android.R.id.list));
//////		((TextView)mHeaderReward.findViewById(R.id.totalearned)).setText(Integer.toString(Constant.totalReward));
////////		if (data != null) {
////////			DataResult result = (DataResult) data;
////////			ExpandableListView listview = ((ExpandableListView)mLayout.findViewById(android.R.id.list));
////////			if (result.getMethodName() == Methods.getOpportunityByStatus) {
////////
////////				String tagname = (String) result.getMethodParam()
////////						.getInputData();
////////
////////				if (tagname.equals(this.getClass().getName())) {
////////					@SuppressWarnings("unchecked")
////////					List<Project> projects = (List<Project>) result.getData();
////////					//mOpportunityBuider.setData(projects);
////////				}
////////				observable.deleteObserver(this);
////////			}
//////			listview.setVisibility(View.VISIBLE);
////////		}
////////		DataResult result = (DataResult) data;
////////		if(result.getMethodName() == Methods.getPreviousRedeem){
////////			Log.e("statement", "get all previous redeem");
////////			mReferenceLoading--;
////////			if(mReferenceLoading == 0) ((BasePagerActivity)getActivity()).hideProgressDialog(R.id.reward_statement_container_loading);
////////			if(result.getData() != null){
////////				Map<Integer, List<Redeem>> map =  (Map<Integer, List<Redeem>>) result.getData();
////////				ExpandableListView listview = ((ExpandableListView)mLayout.findViewById(android.R.id.list));
////////				if(map != null && map.get(0) != null && map.get(0).size() > 0) {
////////					((RedeemAdapter)listview.getExpandableListAdapter()).setPendingRedeem(map.get(0));
////////				}
////////				if(map != null && map.get(1) != null && map.get(1).size() > 0){
////////					((RedeemAdapter)listview.getExpandableListAdapter()).setPreviousRedeem(map.get(1));
////////				}
////////				listview.setVisibility(View.VISIBLE);
////////			}
////////		} else if(result.getMethodName() == Methods.getEarnedStatement){
////////			Log.e("statement", "get earn statement");
////////			mReferenceLoading--;
////////			if(mReferenceLoading == 0) ((BasePagerActivity)getActivity()).hideProgressDialog(R.id.reward_statement_container_loading);
////////			if(result.getData() != null) {
////////				Map<String, Integer> data2 = (Map<String, Integer>) result.getData();
////////				Map<String, Integer> summary = data2;
////////				((TextView)mHeaderReward.findViewById(R.id.totalearned)).setText(Integer.toString(summary.get("Total")));
////////				System.out.println(">>>> Total Earned = " + summary.get("Total"));
////////				//((TextView)mHeaderReward.findViewById(R.id.totalredeem)).setText(Integer.toString(summary.get("Redeemed")));
////////				//((TextView)mHeaderReward.findViewById(R.id.totalbalance)).setText(Integer.toString(summary.get("Balance")));
////////			}
////////		}
//////	}
////	
////	public void init(LayoutInflater inflater,ViewGroup container){
////		if(mLayout == null){
////			mLayout = (ViewGroup) inflater.inflate(R.layout.reward_statement, null, false);
////		}
////		if(listRewardStatement == null){
////			listRewardStatement = (ListView) mLayout.findViewById(R.id.list_reward_statement);
////			}
////		mHeaderReward = inflater.inflate(R.layout.header_reward, null);
////		//((ExpandableListView)mLayout.findViewById(android.R.id.list)).addHeaderView(mHeaderReward,null,false);
////		listRewardStatement.addHeaderView(mHeaderReward);
//////		RedeemAdapter adapter = new RedeemAdapter();
//////		((ExpandableListView)mLayout.findViewById(android.R.id.list)).setAdapter(adapter);
//////		((ExpandableListView)mLayout.findViewById(android.R.id.list)).expandGroup(0);
//////		((ExpandableListView)mLayout.findViewById(android.R.id.list)).setOnChildClickListener(this);
////		//List<Project> lp = ProjectDBHelper.getProjectsByStatus("'Approved'");
////	}	
////	
////
////	@Override
////	public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
////		return new CursorLoader(getActivity(), EMarketingContentProvider.REDEEM_CONTENT_URI, null, null, null, null);
////	}
////
////	@Override
////	public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
////		if(cursor != null && loader.getId() == 0){
////			List<NewReward> rewards = new ArrayList();
////			if(cursor.moveToFirst()){
////				do{
////					NewReward reward = new NewReward();
////					reward.setObjectID(cursor.getInt(cursor.getColumnIndex(RewardDBHelper.RW_OBJECT)));
////					reward.setRewardType(cursor.getString(cursor.getColumnIndex(RewardDBHelper.RW_TYPE)));
////					reward.setRewardAmount(cursor.getInt(cursor.getColumnIndex(RewardDBHelper.RW_AMOUNT)));
////					//reward.setProgramName(cursor.getString(cursor.getColumnIndex(RewardDBHelper.RW_NAME)));
//////					Redeem redeem = new Redeem();
//////					redeem.setId(cursor.getLong(cursor.getColumnIndex(RedeemDBHelper.REDEEM_ID)));
//////					redeem.setPoint(cursor.getInt(cursor.getColumnIndex(RedeemDBHelper.REDEEM_POINT)));
//////					redeem.setProduct(cursor.getString(cursor.getColumnIndex(RedeemDBHelper.REDEEM_PRODUCT)));
//////					redeem.setDate(cursor.getLong(cursor.getColumnIndex(RedeemDBHelper.REDEEM_DATE)));
//////					redeem.setProgramName(cursor.getString(cursor.getColumnIndex(RedeemDBHelper.PROGRAM_NAME)));
//////					redeem.setStatus("Draft");
//////					redeem.setCampaignName(cursor.getString(cursor.getColumnIndex(RedeemDBHelper.CAMPAIGN_NAME)));
//////					redeem.setMaxEligible(cursor.getInt(cursor.getColumnIndex(RedeemDBHelper.MAX_ELIGIBLE)));
//////					redeem.setMinEligible(cursor.getInt(cursor.getColumnIndex(RedeemDBHelper.MIN_ELIGIBLE)));
//////					redeem.setFirstName(cursor.getString(cursor.getColumnIndex(RedeemDBHelper.FIRST_NAME)));
//////					redeem.setLastName(cursor.getString(cursor.getColumnIndex(RedeemDBHelper.LAST_NAME)));
//////					redeem.setMobile(cursor.getString(cursor.getColumnIndex(RedeemDBHelper.MOBILE)));
//////					redeem.setEmail(cursor.getString(cursor.getColumnIndex(RedeemDBHelper.EMAIL)));
//////					redeem.setCountryId(cursor.getInt(cursor.getColumnIndex(RedeemDBHelper.COUNTRY_ID)));
//////					redeem.setStreet(cursor.getString(cursor.getColumnIndex(RedeemDBHelper.STREET)));
//////					redeem.setBuilding(cursor.getString(cursor.getColumnIndex(RedeemDBHelper.BUILDING)));
//////					redeem.setUnit(cursor.getString(cursor.getColumnIndex(RedeemDBHelper.UNIT)));
//////					redeems.add(redeem);
////					rewards.add(reward);
////				} while(cursor.moveToNext());
////
////				if(rewards.size() > 0) {
////					RedeemAdapter adapter = (RedeemAdapter) ((ExpandableListView)mLayout.findViewById(android.R.id.list)).getExpandableListAdapter();
////					adapter.setReward(rewards);
////					mLayout.findViewById(android.R.id.list).setVisibility(View.VISIBLE);
////				}
////			}
////			Log.e("all deal", "on load finish " + loader.getId() + " data size " + rewards.size());
////		}
////		
////	}
////
////	@Override
////	public void onLoaderReset(Loader<Cursor> arg0) {
////		// TODO Auto-generated method stub
////		
////	}
////
////	
////
////	@Override
////	public boolean onChildClick(ExpandableListView parent, View v,
////			int groupPosition, int childPosition, long id) {
//////		if(groupPosition == 0){
//////			Redeem redeem =(Redeem)parent.getExpandableListAdapter().getChild(groupPosition, childPosition);
//////			Intent intent = new Intent(getActivity(), RedeemEdit.class);
//////			intent.putExtra(Constant.INTENT_REDEEM_DETAIL, redeem);
//////			startActivity(intent);
//////		} else if(groupPosition == 1 ||groupPosition == 2 ) {
//////			Redeem redeem =(Redeem)parent.getExpandableListAdapter().getChild(groupPosition, childPosition);
//////			Intent intent = new Intent(getActivity(), RedeemDetail.class);
//////			int indexActivity =((BasePagerActivity)getActivity()).getActivityIndex();
//////			intent.putExtra(IntentKey.ACTIVITY_NAME,  indexActivity);
//////			intent.putExtra(Constant.INTENT_REDEEM_DETAIL, redeem);
//////			startActivity(intent);
//////		}
////		return false;
////	}
////	
////	@Override
////	public void onPause() {
////		super.onPause();
////		//DataHelper.getInstance().deleteObserver(this);
////	}
//	
//}
